import UiManager from "./UiManage";

const {ccclass, property} = cc._decorator;

@ccclass
export default class FundRewardBoxItemCtrl extends cc.Component {
@property(cc.Node)
ui = null;

@property
index = null;

@property
haveSelect = false;

onLoad() {
    this.onUILoad();
    this.addButtonListen();
}

start() {}

onUILoad() {
    this.ui = this.node.addComponent(u);
    var e = f[this.index];
    var t = g[e - 1];
    var a = this.ui.spineNode.getComponent(sp.Skeleton);
    a.setSkin(t);
    var o = Math.random() + s.getRandomNum(0, 1);
    this.scheduleOnce(function() {
        s.playSpine(a, "idle1", true);
    }, o);
}

initData(e) {
    if (e) {
        this.index = e.index;
    }
}

addButtonListen() {
   UiManager.addButtonListen(this.ui.box, this.clickReward, this, 0, "click_box");
}

closeSchedule() {
    this.unscheduleAllCallbacks();
}

clickReward() {
    var e = this;
    this.ui.box.getComponent(cc.Button).interactable = false;
    this.haveSelect = true;
    this.closeSchedule();
    var t = this.ui.spineNode.getComponent(sp.Skeleton);
    s.playSpine(t, "open", false, function() {
        e.ui.box.active = false;
        e.changeRewardSp(true);
        e.setRewardFund("428元", true);
        e.scheduleOnce(function() {
            n.trigger(l.FUND_BOX_OPEN_DONE);
        }, 0.5);
    });
    n.trigger(l.SHOW_GUIDE_FUND_REWARD);
}

setCanClick(e) {
    this.ui.box.getComponent(cc.Button).interactable = e;
}

playBoxSpine(e, t, a) {
    void 0 === a && (a = null);
    var o = this.ui.spineNode.getComponent(sp.Skeleton);
    s.playSpine(o, e, t, function() {
        a && a();
    });
}

changeRewardSp(e) {
    var t = this;
    this.ui.fundRewardNode.active = true;
    var a = "fund_gray";
    if (e) {
        this.ui.rewrdNode.opacity = 255;
        a = "fund_green";
    } else this.ui.rewrdNode.opacity = 0;
   UiManager.loadSpriteFrame(this.ui.rewrdNode, "fundReward", a, function() {
        if (!e) {
            cc.tween(t.ui.rewrdNode).to(0.5, {
                opacity: 255
            }).start();
        }
    });
}

setLightShow(e) {
    this.ui.light.active = e;
}

setRewardFund(e, t) {
    void 0 === t && (t = false);
    var a = "<outline color=#0E7D08 width=1><color=#FFFFFF>" + e + "</color></outline>";
    if (!t) {
        a = "<outline color=#4F4F4F width=1><color=#FFFFFF>" + e + "</color></outline>";
    }
    this.ui.fundCashLabel.getComponent(cc.RichText).string = a;
}

setBoxShow(e) {
    var t = this;
    if (e) {
        this.ui.box.active = e;
    } else {
        cc.tween(this.ui.box).to(0.5, {
            opacity: 0
        }).call(function() {
            t.ui.box.active = false;
        }).start();
    }
}

static prefabUrl = "assets/resources/prefabs/FundRewardBoxItem";
static className = "FundRewardBoxItemCtrl";
}